﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using V2TEK.NET.SH.Silverlight.Charts.Core.Schedule;
using System.Globalization;

namespace V2TEK.NET.SH.Silverlight.Charts.TimeLineHelper
{

    /// <summary>
    /// zh-cn
    /// </summary>
    public class QuaterDateTimeFormmater2 : IFormatProvider, ICustomFormatter
    {
        #region IFormatProvider Members

        public object GetFormat(Type formatType)
        {
            if (formatType == typeof(ICustomFormatter))
                return this;
            else
                return null;

        }

        #endregion

        #region ICustomFormatter Members

        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            DateTime dt = (DateTime)arg;
            return dt.ToString("yyyy") + core.Year + (dt.Month + 2) / 3 + core.Quater;
        }

        #endregion
    }


    public class SimpleDateTimeDescriptor2 : IDateTimeDescriptor
    {
        public SimpleDateTimeDescriptor2(int range, DateTimeType dateTimeType)
        {
            this.DateTimeType = dateTimeType;
            this.Range = range;
        }

        #region const & static
        private static IFormatProvider _quarter;
        public string Minute = core.S_Formatter_Min;// "yyyy年MM月dd日HH时";
        public string Hour = core.S_Formatter_Hour;// "yyyy年MM月dd日HH时";
        public string WeekDay = core.S_Formatter_WeekDay;// "yyyy年MM月dd日";
        public string Day = core.S_Formatter_Day;// "yyyy年MM月dd日";
        public string Week = core.S_Formatter_Week;// "yyyy年MM月dd日(ddd)";
        public string Month = core.S_Formatter_Month; // "yyyy年MM月dd日";
        public string BigMonth = core.S_Formatter_BigMonth;// "yyyy年MMM";
        public string Year = core.S_Formatter_Year;// "yyyy年";

        public static IFormatProvider Quarter
        {
            get
            {
                if (_quarter == null)
                    _quarter = new QuaterDateTimeFormmater2();
                return _quarter;
            }
        }
        #endregion

        private IFormatProvider localProvider;

        public IFormatProvider LocalProvider
        {
            get
            {
                if (localProvider == null)
                    localProvider = new CultureInfo(core.CultureInfo);
                return localProvider;
            }
            set
            {
                localProvider = value;
            }
        }

        #region IDateTimeDescriptor Members

        public DateTime Date
        {
            get;
            set;
        }

        public int Range
        {
            get;
            set;
        }

        public object Description
        {
            get
            {
                switch (this.DateTimeType)
                {
                    case DateTimeType.Minute:
                        return Minute;
                    case DateTimeType.Hour:
                        return Hour;
                    case DateTimeType.WeekDay:
                        return WeekDay;
                    case DateTimeType.Day:
                        return Day;
                    case DateTimeType.Week:
                        return Week;
                    case DateTimeType.Month:
                        return Month;
                    case DateTimeType.BigMonth:
                        return BigMonth;
                    case DateTimeType.Quarter:
                        return Quarter;
                    default:
                        return Year;
                }
            }
            set { }
        }

        public DateTimeType DateTimeType
        {
            get;
            set;
        }

        public TimeSpan DateTimeRange
        {
            get
            {
                return DateTimeHelper.GetDateTimeRange(this.Date, this.DateTimeType, Range);
            }
        }

        public string DisplayText
        {
            get
            {
                if (Description is ICustomFormatter)
                    return (Description as ICustomFormatter).Format(string.Empty, this.Date, null);
                if (Description is IFormatProvider)
                    return this.Date.ToString(Description as IFormatProvider);
                return this.Date.ToString(Description.ToString(), LocalProvider);
            }
        }

        /// <summary>
        /// 格式化Date输出
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.DateTimeRange.TotalMilliseconds.ToString();
        }

        public IDateTimeDescriptor Clone()
        {
            return new SimpleDateTimeDescriptor2(this.Range,this.DateTimeType);
        }

        #endregion
    }
}
